package com.wsbombphoto.resource;

import java.util.ArrayList;

import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

import com.wsbombphoto.controller.UserController;
import com.wsbombphoto.model.User;

@Path("/Users")
public class UserResource {

	@GET
	@Path("/listAll")
	@Produces("application/json")
	public ArrayList<User> listAll() {
		return new UserController().listAll();
	}

	@GET
	@Path("/getUser")
	@Produces("application/json")
	public User getUser(@PathParam("iduser") int idUser) {
		return new UserController().getUser(idUser);
	}

	@POST
	@Path("Login")
	@Consumes("application/x-www-form-urlencoded")
	public Response getLogin(@FormParam("username") String userName,
			@FormParam("password") String password) {
		User user = new UserController().getLogin(userName, password);
		if (user != null) {
			return Response.status(200).entity(user).build();
		} else {
			return Response.status(204).build();
		}
	}

}
